﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Backend.JYD.Model.Task;
using Backend.JYD.Model;

namespace Backend.JYD.BLL.Task
{
    public class TaskStepInfoBLL
    {
        private static readonly IDAL.Task.ITaskStepInfo idal = Factory.DALFactory.CreateEFDAL<IDAL.Task.ITaskStepInfo>("DAL.TaskStepInfoDAL");

        public Int64 AddTaskStepInfo(TaskStepInfo info)
        {
            if (info.TaskId <= 0) return 0;
            if (string.IsNullOrWhiteSpace(info.RoleIds) && string.IsNullOrWhiteSpace(info.EmpIds)) return 0;
            if (info.StepId <= 0) return 0;
            return idal.AddTaskStepInfo(info);
        }

        public bool UpdateTaskStepInfo(TaskStepInfo info)
        {
            if (info.TaskId <= 0) return false;
            if (info.TaskDetailId <= 0) return false;
            if (string.IsNullOrWhiteSpace(info.RoleIds) && string.IsNullOrWhiteSpace(info.EmpIds)) return false;
            if (info.StepId <= 0) return false;

            return idal.UpdateTaskStepInfo(info);
        }

        public TaskStepInfo GetTaskStepInfoByTaskDetailId(Int64 taskDetailId)
        {
            if (taskDetailId <= 0) return null;
            return idal.GetTaskStepInfoByTaskDetailId(taskDetailId);
        }

        public PageInfo<TaskStepInfo> GetTaskStepInfoByPage(PageInfo page)
        {
            return idal.GetTaskStepInfoByPage(page);
        }

        public PageInfo<TaskStepInfo> GetTaskStepInfoByEmpInfo(PageInfo page, Int64 roleId, Int64 empId, string status)
        {
            return idal.GetTaskStepInfoByEmpInfo(page, roleId, empId, status);
        }

        public IList<TaskStepInfo> GetTaskFirstStepInfoByTaskIds(IList<Int64> taskIds)
        {
            if (taskIds != null || taskIds.Count <= 0) return null;
            return idal.GetTaskFirstStepInfoByTaskIds(taskIds);
        }

        public List<TaskStepInfo> GetTaskStepInfoByTaskId(Int64 taskId)
        {
            if (taskId <= 0) return null;
            var list = idal.GetTaskStepInfoByTaskId(taskId);
            return list == null ? null : list.ToList();
        }

        public bool AssignTaskStepInfo(TaskStepInfo info)
        {
            if (info.TaskId <= 0) return false;
            if (string.IsNullOrWhiteSpace(info.RoleIds) && string.IsNullOrWhiteSpace(info.EmpIds)) return false;
            if (info.StepId <= 0) return false;
            return idal.AddTaskStepInfo(info) > 0;
        }
    }
}
